package com.jackiechancinema.ssm.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import com.jackiechancinema.ssm.dao.MoviceDao;
import com.jackiechancinema.ssm.dto.MoviceE;
import com.jackiechancinema.ssm.entity.Movices;
import com.jackiechancinema.ssm.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
public class MoviceEx extends AnalysisEventListener<MoviceE> {


    @Autowired
    private MoviceDao moviceDao;

    private List<Movices> list=new ArrayList<>();
    //获取读取到的每一行对应的对象
    @Override
    public void invoke(MoviceE moviceE, AnalysisContext analysisContext) {
        System.out.println("ccc");
        //实现属性的赋值
        Movices movices = BeanUtil.copyProperty(Movices.class,moviceE,moviceE.getClass().getDeclaredFields());


        //添加到集合
        list.add(movices);
        System.out.println(list);

    }
    //整个读取结束
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //将读取的数据一次性的存储到数据库
        int r=moviceDao.insertBatch(list);
        list.clear();
    }
}
